package com.example.springboot.mapper;

import com.example.springboot.entity.Note;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NoteMapper {
    @Select("SELECT * FROM Notes WHERE id = #{id}")
    Note findById(@Param("id") Integer id);

    @Select("SELECT * FROM Notes WHERE user_id = #{userId} LIMIT #{pageNum}, #{pageSize}")
    List<Note> findByUserId(@Param("userId") Integer userId,@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
    @Select("SELECT * FROM Notes WHERE user_id = #{userId} And importance = #{importance}  LIMIT #{pageNum}, #{pageSize}")
    List<Note> findByUserIdAndImportance(Integer userId, int pageNum, int pageSize, Integer importance);
    @Insert("INSERT INTO Notes (user_id, title, tags, content, importance, created_at, updated_at) " +
            "VALUES (#{userId}, #{title}, #{tags}, #{content}, #{importance}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Note note);

    @Update("UPDATE Notes SET title = #{title}, tags = #{tags}, content = #{content}, " +
            "importance = #{importance}, updated_at = NOW() WHERE id = #{id}")
    void update(Note note);

    @Delete("DELETE FROM Notes WHERE id = #{id}")
    void delete(@Param("id") Integer id);


}
